package com.example.utils;

import com.example.model.LoginUser;
import com.example.model.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Author by admin, Email xx@xx.com, Date on 2020/5/28.
 * PS: Not easy to write code, please indicate.
 */
public class authUtils {
    public static User getuser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
            if(!"anonymousUser".equals(authentication.getPrincipal()))
            {
               return loginUser.getUser();
            }
            return null;
        }
    }

